package org.particlethink.quartz;

import org.particlethink.job.Runnable;
import org.particlethink.singleflight.SingleFlight;
import org.springframework.beans.factory.BeanFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Configuration;
import org.springframework.scheduling.annotation.EnableScheduling;
import org.springframework.scheduling.annotation.Scheduled;

// todo 后续可以做定时优化

@Configuration
@EnableScheduling
public class QuartzConfig {

    @Autowired
    private BeanFactory beanFactory;

    private final SingleFlight singleFlight = new SingleFlight();

    @Scheduled(cron = "0/10 * * * * ?")
    public void proSupplierMapperImpl() {
        Runnable<Object> quartzRunnable = beanFactory.getBean("proSupplierMapperImpl", Runnable.class);
        singleFlight.Do("proSupplierMapperImpl", quartzRunnable);
    }


}
